package net.bezrabotnih.cabinet.client.ui;

import java.util.logging.Logger;

import net.bezrabotnih.cabinet.client.activity.ProviderJobsActivity;
import net.bezrabotnih.client.managed.request.JobProxy;
import net.bezrabotnih.client.managed.request.UserAccountProxy;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;

public class DoneJobView extends Composite {

	private static final Logger log = Logger.getLogger(DoneJobView.class.getName());
	
	private static DoneJobViewUiBinder uiBinder = GWT
			.create(DoneJobViewUiBinder.class);

	interface DoneJobViewUiBinder extends UiBinder<Widget, DoneJobView> {
	}
	
	public interface Presenter{

		void showJob(JobProxy jobProxy);

		void ratingButtonClicked(JobProxy jobProxy,UserAccountProxy winner);

		void reCreateButtonClicked(JobProxy jobProxy);
		
	}
	
	private Presenter listener;
	@UiField
	Anchor jobLink;
	@UiField
	Button ratingButton;
	@UiField
    Button reCreateButton;
	
	private JobProxy jobProxy;
	private UserAccountProxy winner;
	
	public DoneJobView(Presenter listener,JobProxy jobProxy,UserAccountProxy winner) {
		initWidget(uiBinder.createAndBindUi(this));
		this.listener=listener;
		this.jobProxy=jobProxy;
		this.jobLink.setText(jobProxy.getName());
		log.info("new Done Job created, name:"+jobProxy.getName());
		
	}
	
	@UiHandler("jobLink")
	void onJobLinkClick(ClickEvent event){
		listener.showJob(jobProxy);
	}
	
	@UiHandler("ratingButton")
	void onRatingButtonClick(ClickEvent event){
		listener.ratingButtonClicked(jobProxy,winner);
	}
	
	@UiHandler("reCreateButton")
	void onReCreateButtonClick(ClickEvent event){
		listener.reCreateButtonClicked(jobProxy);
	}

}
